package cs3343.project.family;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileNameExtensionFilter;

public class FileChooser {

	public FileChooser() {
		JFileChooser chooser = new JFileChooser();
		chooser.setCurrentDirectory(new File("."));
		
		chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
			public boolean accept(File f) {
				return f.getName().toLowerCase().endsWith(".jpg"); //限定顯示.xls為結尾的檔案
				//`f.isDirectory();
			}
		
			public String getDescription() {
				return "Excel files";
			}
		});

		int r = chooser.showOpenDialog(new JFrame());
		if (r == JFileChooser.APPROVE_OPTION) {
			String name = chooser.getSelectedFile().getPath();// .getName(); //getpath回傳檔案路徑加上檔案名稱，getname只回傳檔案名稱
			// System.out.println(name);
		}
	}
}
